define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'recharge/order/index' + location.search,
                    add_url: 'recharge/order/add',
                    edit_url: 'recharge/order/edit',
                    del_url: 'recharge/order/del',
                    multi_url: 'recharge/order/multi',
                    import_url: 'recharge/order/import',
                    table: 'recharge_order',
                }
            });

            var table = $("#table");

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#pay_money").text(data.extend.pay_money);
                $("#gift_money").text(data.extend.gift_money);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                        {field: 'pay_money', title: __('Pay_money'), operate:false},
                        {field: 'money', title: __('Money'), operate:false},
                        {field: 'gift_money', title: __('Gift_money'), operate:false},
                        {field: 'user_id', title: __('User_id'), operate:false},
                        {field: 'order_time', title: __('Order_time'), operate:false, addclass:'datetimerange', autocomplete:false},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'pay_type', title: __('Pay_type'), operate:false, searchList: {"alipay":__('Pay_type alipay'),"wechat":__('Pay_type wechat'),"adapay_wx_pub": 'adapay微信'}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"10":__('Status 10'),"20":__('Status 20')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
